import model from './model'
import API from '../API/dashboard'

export default {
  /**
   * 混入（列表）
   */
  data() {
    return {
      model: model(),
      API: API,
    }
  },
  computed: {

  },
  methods: {
    init() {
      this.getAlarmTotal()
      this.getAlarmLevelTotal()
      this.getAlarmResolveStateTotal()
      this.getAlarmPerHourTotal()
      this.getAlarmSubSystemTotal()
    },
    /**
     * @description:告警总数
     */
    async getAlarmTotal() {
      const [quantity] = await this.API.getAlarmTotal()
      this.model.alarmTotal = quantity
    },
    /**
     * @description:告警统计（等级）
     */
    async getAlarmLevelTotal() {
      const [content] = await this.API.getAlarmLevelTotal()
      this.model.assetDetailPieSourceList = content.map((item) => {
        return { name: item.name, value: item.quantity }
      })
    },
    /**
     * @description:告警统计（状态）
     */
    async getAlarmResolveStateTotal() {
      const [content] = await this.API.getAlarmResolveStateTotal()
      this.model.alarmResolveStateTotal = content.map((item) => {
        return { name: item.name, value: item.quantity }
      })
    },
    /**
     * @description:告警趋势
     */
    async getAlarmPerHourTotal() {
      const [content] = await this.API.getAlarmPerHourTotal()
      const seriesData = []
      this.model.assetDetailLineXAxisList = []
      content.forEach((item, i) => {
        seriesData.push(item.quantity)
        // seriesData.push(10 + i)
        this.model.assetDetailLineXAxisList.push(item.name)
      })
      this.model.assetDetailLineSourceList = [
        {
          color: '#FF594D',
          data: seriesData,
          type: 'line',
          showSymbol: false,
          smooth: true,
        },
      ]
    },
    /**
     * @description:告警分布
     */
    async getAlarmSubSystemTotal() {
      const [content] = await this.API.getAlarmSubSystemTotal()
      const seriesData = []
      this.model.assetDetailBarXAxisList = []
      content.forEach((item) => {
        seriesData.push(item.quantity)
        this.model.assetDetailBarXAxisList.push(item.name)
      })
      this.model.assetDetailBarSourceList = [
        {
          color: '#C5362C',
          data: seriesData,
          type: 'bar',
          barWidth: 10,
          itemStyle: { borderRadius: [10, 10, 10, 10] },
        },
      ]
    },
  },
  created() {
    this.init()
  },
}
